
const Check = { template: `
	<div>
		<mt-header title="盘点"></mt-header>
		
		<mt-cell v-if="column_idx == -1" title="请选择列" >
		  <span style="color: green"><mt-button size="small" type="primary"  @click="show_columns()" >选择</mt-button></span>
		</mt-cell>
		<div v-if="column_idx != -1" >
			<mt-cell :title="'第'+(column_idx+1)+'列'" >
			  <span style="color: green"><mt-button size="small" type="primary"  @click="show_columns()" >选择</mt-button></span>
			</mt-cell>


		
			<mt-cell v-if="section == ''" title="请选择节" >
			  <span style="color: green"><mt-button size="small" type="primary"  @click="show_sections()" >选择</mt-button></span>
			</mt-cell>

			<mt-cell v-if="section != ''" :title="'第'+section+'节'" >
			  <span style="color: green"><mt-button size="small" type="primary"  @click="show_sections()" >选择</mt-button></span>
			</mt-cell>

			
			<mt-cell v-if="layer !=  -1" :title="'第'+(layer+1)+'层'" >
			  <span style="color: green"><mt-button size="small" type="primary"  @click="show_layers()" >选择</mt-button></span>
			</mt-cell>
			
			<mt-cell v-if="layer == -1" title="请选择层" >
			  <span style="color: green"><mt-button size="small" type="primary"  @click="show_layers()" >选择</mt-button></span>
			</mt-cell>

		</div>

		<mt-actionsheet
		  :actions="columns"
		  v-model="columns_visible">
		</mt-actionsheet>

		
		<mt-actionsheet
		  :actions="sections"
		  v-model="sections_visible">
		</mt-actionsheet>
		<mt-actionsheet
		  :actions="layers"
		  v-model="layers_visible">
		</mt-actionsheet>



		<br/>
        <mt-button size="large" v-if="column_idx != -1" type="primary" @click="add()"> 增加盘点清单</mt-button>

		
		<div v-for = "(item, i) in checks">

			<mt-cell  v-if="item.layer!= -1 && item.section != -1"  :title="'选择器:'+(i+1)" is-link :label="room +'-'+area+'区 '+(item.column+1)+'列'+(item.layer+1)+'层'+(item.section+1)+'节'">
				<mt-button size="small" type="primary"  @click="del(i)" >删除</mt-button>   
			</mt-cell>

			
			<mt-cell  v-if="item.layer== -1 && item.section != -1"  :title="'选择器:'+(i+1)" is-link :label="room +'-'+area+'区 '+(item.column+1)+'列'+(item.section+1)+'节'">
				<mt-button size="small" type="primary"  @click="del(i)" >删除</mt-button>   
			</mt-cell>

			
			
			<mt-cell  v-if="item.layer!= -1 && item.section == -1"  :title="'选择器:'+(i+1)" is-link :label="room +'-'+area+'区 '+(item.column+1)+'列'+(item.layer+1)+'层'">
				<mt-button size="small" type="primary"  @click="del(i)" >删除</mt-button>   
			</mt-cell>

			
			<mt-cell  v-if="item.layer == -1 && item.section == -1"  :title="'选择器:'+(i+1)" is-link :label="room +'-'+area+'区 '+(item.column+1)+'列'">
				<mt-button size="small" type="primary"  @click="del(i)" >删除</mt-button>   
			</mt-cell>
		</div>


		
        <mt-button size="large" type="primary" v-if="checks.length != 0" @click="save()"> 保存</mt-button>

		<div v-for = "(item, i) in list">
			<mt-cell :title="item.doc_name" :label="room +'-'+area+'区 '+(getColumn(item.area, item.column)+1)+'列'+(item.layer+1)+'层'+(item.section+1)+'节'"></mt-cell>
 
		</div>

		


	</div>


`,
    data () {
  	return {
		layer:-1,
		layers:[],
		layers_visible: false,
		section:"",
		sections:[],
		sections_visible: false,
		column_idx:-1,
		columns: [],
      // action sheet 默认不显示，为false。操作sheetVisible可以控制显示与隐藏
		columns_visible: false,

		checks:[],
  		//存放所选选项
			left:[],
			right:[],
			value:[],
			left_value:["a"],
			right_value:["a"],
			select:[],
			get:"test",
			data:value,
			area:this.$route.params.area,
			room:this.$route.params.room,
			list:[],
			goods:[],
  		}
    },

	 created () {
    
       this.$parent.bar_show = true;
       this.fetchData();
	   this.init();
    },
    watch: {
        // 如果路由有变化，会再次执行该方法
        '$route': 'fetchData'
    },
    //检查是否有数据，有则进入，无则初始化
     
	methods:
	{

		getColumn(area, index){
			for(let i=0; i<this.data.cabinets.item.length; ++i){

				if(this.data.cabinets.item[i].area == area && this.data.cabinets.item[i].index == index){
					return i;
				}
			}
			return -1;//this.data.cabinets.item[index].index;
		},
		del:function(idx){
			this.checks.splice(idx, 1);
			this.load();
		},
		actionSheet: function(){
			this.sheetVisible = true;
		},
		getColumn(area, index){
			for(let i=0; i<this.data.cabinets.item.length; ++i){

				if(this.data.cabinets.item[i].area == area && this.data.cabinets.item[i].index == index){
					return i;
				}
			}
			return -1;//this.data.cabinets.item[index].index;
		},
		show_columns: function(){
			this.columns_visible = true;
		},
		show_sections: function(){
			this.sections_visible = true;
		},
		show_layers: function(){
			this.layers_visible = true;
		},
		
		add: function(){
			const self = this;
			this.checks.push({column:self.column_idx, layer:(self.layer), section:(self.section*1-1)});
			
			self.load();
			self.column_idx = -1;
			self.section = '';
			self.layer = -1;
		},
		save:function(){
			var self = this;
			axios.post("/geek/"+this.room+"/"+this.area+"/check/upload", {checks:self.checks, list:self.list, a:2})
			.then(function(res){
				self.get = res.data;
				
				alert(res.data);
			}).catch(function (error) {
				alert(error);
			});
		},
		load:function(){
			const self = this;
			this.list = [];
			for(let i =0 ;i<self.goods.length; ++i){
			
				let item = this.goods[i];
				if(this.check(item)){
					let item = this.goods[i];
					this.list.push(item);
				}
			}
		},
		check:function(item){

			for(let i=0; i<this.checks.length; ++i){
				let check = this.checks[i];
				
				let it = this.data.cabinets.item[check.column];

				if(it.area == item.area && it.index == item.column){
					if(check.layer != -1 && check.layer  != item.layer){
						continue;
					}
					if(check.section != -1 && check.section  != item.section){
						continue;
					}
					return true;
				}


				//{column:self.column_idx, layer:(self.layer), section:(self.section*1-1)}
			}
			return false;
			
		},
		init:function(){
		
		//http://localhost:3000/geek/A/01/check/download

			var self = this;
			axios.get("/geek/"+this.room+"/"+this.area+"/check/download",
			{
			}).then(function(res){
			
				let data = res.data;
				self.list =  JSON.parse(data.list)
				self.checks =  JSON.parse(data.check)

            
            
			}).catch(function (error) {
				alert(error);
			});


		
		},
		refresh: function(){
			var self = this;
			this.list = [];
			for(let i=0; i<this.goods.length; ++i){
				let item = this.goods[i];
				if(this.check(item)){
					this.list.push(item);
					
					
				}
			}
			self.left =[];
			self.right =[];
			for(let i=0; i<this.value.length; ++i){
				let idx = this.value[i]-1;
				let it = this.data.cabinets.item[idx];
				self.get = it;
				self.left[idx] =it.left;
				self.right[idx] =it.right;
			}
			/*
			for(let i=0; i<this.value.length; ++i){
				let idx = this.value[i]-1;
			}*/
		},
		fetchData () {
			var self = this;
			axios.get("/geek/"+this.room+"/"+this.area+"/setupTable",
			{
			}).then(function(res){
			
				self.data = res.data;
				self.columns = [];
				for(let i =0 ;i<self.data.cabinets.item.length; ++i){
					let item = self.data.cabinets.item[i];
					self.columns.push( {name: '第'+(i+1)+'列',method : function(){self.column_idx = i;}});
					
					self.sections = [];
					for(let j=0;j<item.left.length;++j){
						self.sections.push( {name: '第'+item.left[j]+'节',method : function(){self.section =item.left[j];}});
					}
					for(let j=0;j<item.right.length;++j){
						self.sections.push( {name: '第'+item.right[j]+'节',method : function(){self.section =item.right[j];}});
					}
					
					self.layers = [];
					for(let j=0;j<item.layers;++j){
						self.layers.push( {name: '第'+(j+1)+'层',method : function(){self.layer =j;}});
					}

				}

				
				self.columns.push( {name: '释放',method : function(){self.column_idx = -1;}});
				self.sections.push( {name: '释放',method : function(){self.section ="";}});
				self.layers.push( {name: '释放',method : function(){self.layer =-1;}});



				self.reload();
            
            
			}).catch(function (error) {
				alert(error);
			});
		},
		   
		reload(){

			Vue.$indicator.open();
			let self = this;
			let url = "/geek/"+this.room+"/"+this.area+"/archives?";
			this.get = self.data;
			for(let n =0 ;n<self.data.cabinets.areas.length; ++n){
				url += "area="+self.data.cabinets.areas[n]+'&';
			}
			//alert(url);
			axios.get(url,
			{
       
			}).then(function(res){
				self.goods = res.data;
				console.log(self.goods);
				Vue.$indicator.close();
			}).catch(function (error) {
				console.log(error);
				Vue.$indicator.close();
			});
		},
   
	},
}